/*
 * @Author: your name
 * @Date: 2022-04-26 16:53:08
 * @LastEditTime: 2022-04-28 17:01:20
 * @LastEditors: Please set LastEditors
 * @Description: jwt 文件
 * @FilePath: \vue-vite-api\src\modules\user\entities\jwt.strategy.ts
 */

import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { jwtConstants } from './jwt.contants';
import { ExtractJwt, Strategy } from 'passport-jwt';
// import 

// import { ConfigService } from '@nestjs/config';
// import { StrategyOptions, Strategy, ExtractJwt } from 'passport-jwt';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
    constructor() {
        super({
            // 获取请求header token值
            jwtFromRequest: ExtractJwt.fromHeader('token'),
            secretOrKey: jwtConstants.secret,
        });
    }
    async validate(payload: any) {
        console.log('payload', payload);
        // payload：jwt-passport认证jwt通过后解码的结果
        return { username: payload.username, id: payload.sub };
    }
}
